﻿import store from '/vue/store/index.js';
import { debounce } from "/vue/utils/index.js";

export default {
    data() {
        return {
            mytableHeight: 100,
            hasPage:true
        }
    },
    methods: {
        ElTableResizeHandler() {

            var this_ = this;

            debounce(() => {

                var jTable, jPage;

                new Promise((resolve, reject) => {
                    function check() {
                        try {
                            jTable = $(this_.$refs.mytable.$el);
                            if (this_.hasPage) {
                                jPage = $(this_.$refs.mypage.$el);
                            } else {
                                jPage = {};
                            }
                            resolve(null);
                            return;
                        }
                        catch (err) {
                            setTimeout(check, 100);
                        }
                    }
                    check();
                }).then(() => {
                    this_.mytableHeight = $(window).height() - jTable.offset().top - (this_.hasPage ? jPage.outerHeight(true) : 0);
                    $(jTable.find('.el-table__body-wrapper')).mCustomScrollbar({
                       
                        theme: "minimal-dark"
                    });
                }, err => {
                        console.info("ElTableResizeHandler",err)
                });
            }, 100)();
        }
    },
    computed: {
        ElTableTagsView() {
            return store.state.settings.tagsView;
        }
    },
    mounted() {
        window.addEventListener("resize", this.ElTableResizeHandler);
    },
    beforeDestroy() {
        window.addEventListener("resize", this.ElTableResizeHandler);
    },
    watch: {
        ElTableTagsView() {
            this.ElTableResizeHandler();
        }
    }
}